package com.svpino.netflix;

import java.util.List;

import com.svpino.netflix.model.Title;
import com.svpino.netflix.parsers.TitleParser;


public class TitlesContext extends AbstractQueryable<Title> {

	public TitlesContext(ProxyImpl connection) {
		super(connection);
	}

	public TitlesContext term(String value) {
		getParameters().remove("term");
		getParameters().put("term", value);
		return this;
	}

	public TitlesContext expand(Branch branch) {
		String value = branch.getIdentifier();
		if (getParameters().containsKey("expand")) {
			value = getParameters().remove("expand") + "," + value;
		}

		getParameters().put("expand", value);
		return this;
	}

	public TitlesContext start(int value) {
		getParameters().put("start_index", new Integer(value).toString());
		return this;
	}

	public TitlesContext take(int value) {
		getParameters().put("max_results", new Integer(value).toString());
		return this;
	}

	@Override
	public List<Title> list() {
		return new TitleParser(getConnection()).list(getUrl(Constants.RESOURCE_CATALOG_TITLES));
	}
}
